#include <stdio.h>


//StringFromConsole.c
#include <stdlib.h>

struct Ch
{
	char c;
	struct Ch* p;
};

char* LinklistToCharArray(struct Ch* singleChar, unsigned count)
{
	char* array = (char*)malloc(count*sizeof(char));
	char* c = array;
	struct Ch *nCh = singleChar;
	while (nCh != NULL) {
		*(c++) = nCh->c;
		nCh = nCh->p;
	}
	*c = '\0';
	return array;
}

char* GetStringFromConsole()
{
	struct Ch* header=(struct Ch*)malloc(sizeof(struct Ch));
	struct Ch* oCh=header;
	char c = 0;
	unsigned count = 0;
	
	// first time
	oCh->c = getchar();
	oCh->p = NULL;
	
	// then ...
	while (c=getchar()) {
		// malloc new node
		struct Ch* nCh = (struct Ch*)malloc(sizeof(struct Ch));
		nCh->p = NULL;
		nCh->c = c;
		// last node point to new one
		oCh->p = nCh;
		oCh = nCh;
		// count the length of string
		++count;
		if (c=='\n') break;
	}
	return LinklistToCharArray(header, count);
}
// end of file

int main(int argc, char *argv[])
{
	char* p = GetStringFromConsole();
	printf("%s", p);
	system("pause");
	return 0;
}





